package gdconf

import (
	"server_cluster/common/logger"
)

// 角色配置表

type RoleConfig struct {
	RoleId              int32    `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 角色id
	WeaponAllowTypeList IntArray `csv:"WeaponType,omitempty"`                      // 允许武器类型
	WeaponMainType      int32    `csv:"Weapon,omitempty"`                          // 武器大类型
	ConvItem            *Item    `csv:"Decompose,omitempty"`                       // 重复转化道具列表
	LevelGroup          int32    `csv:"LevelGroup,omitempty"`                      // 等级组
	PromoteGroup        int32    `csv:"PromoteGroup,omitempty"`                    // 等阶组
	StarGroup           int32    `csv:"StarGroup,omitempty"`                       // 星级组
	TalentGroup         int32    `csv:"TalentGroup,omitempty"`                     // 天赋组
	TagList             int32    `csv:"RoleTag,omitempty"`                         // 角色标签

	FightCycleProp *FightProp `csv:"BattleAttribute,omitempty"` // 战斗循环属性
	FightProp1     *FightProp `csv:"Attribute1,omitempty"`      // 战斗属性1
	FightProp2     *FightProp `csv:"Attribute2,omitempty"`      // 战斗属性2
	FightProp3     *FightProp `csv:"Attribute3,omitempty"`      // 战斗属性3
	FightProp4     *FightProp `csv:"Attribute4,omitempty"`      // 战斗属性4
	FightProp5     *FightProp `csv:"Attribute5,omitempty"`      // 战斗属性5
	FightProp6     *FightProp `csv:"Attribute6,omitempty"`      // 战斗属性6
	FightProp7     *FightProp `csv:"Attribute7,omitempty"`      // 战斗属性7
	FightProp8     *FightProp `csv:"Attribute8,omitempty"`      // 战斗属性8
	FightProp9     *FightProp `csv:"Attribute9,omitempty"`      // 战斗属性9
	FightProp10    *FightProp `csv:"Attribute10,omitempty"`     // 战斗属性10
	FightProp11    *FightProp `csv:"Attribute11,omitempty"`     // 战斗属性11
	FightProp12    *FightProp `csv:"Attribute12,omitempty"`     // 战斗属性12
	FightProp13    *FightProp `csv:"Attribute13,omitempty"`     // 战斗属性13
	FightProp14    *FightProp `csv:"Attribute14,omitempty"`     // 战斗属性14
	FightProp15    *FightProp `csv:"Attribute15,omitempty"`     // 战斗属性15
	FightProp16    *FightProp `csv:"Attribute16,omitempty"`     // 战斗属性16
	FightProp17    *FightProp `csv:"Attribute17,omitempty"`     // 战斗属性17
	FightProp18    *FightProp `csv:"Attribute18,omitempty"`     // 战斗属性18
	FightProp19    *FightProp `csv:"Attribute19,omitempty"`     // 战斗属性19
	FightProp20    *FightProp `csv:"Attribute20,omitempty"`     // 战斗属性20
	FightProp21    *FightProp `csv:"Attribute21,omitempty"`     // 战斗属性21
	FightProp22    *FightProp `csv:"Attribute22,omitempty"`     // 战斗属性22
	FightProp23    *FightProp `csv:"Attribute23,omitempty"`     // 战斗属性23
	FightProp24    *FightProp `csv:"Attribute24,omitempty"`     // 战斗属性24
	FightProp25    *FightProp `csv:"Attribute25,omitempty"`     // 战斗属性25
	FightProp26    *FightProp `csv:"Attribute26,omitempty"`     // 战斗属性26
	FightProp27    *FightProp `csv:"Attribute27,omitempty"`     // 战斗属性27
	FightProp28    *FightProp `csv:"Attribute28,omitempty"`     // 战斗属性28
	FightProp29    *FightProp `csv:"Attribute29,omitempty"`     // 战斗属性29
	FightProp30    *FightProp `csv:"Attribute30,omitempty"`     // 战斗属性30
	FightProp31    *FightProp `csv:"Attribute31,omitempty"`     // 战斗属性31
	FightProp32    *FightProp `csv:"Attribute32,omitempty"`     // 战斗属性32
	FightProp33    *FightProp `csv:"Attribute33,omitempty"`     // 战斗属性33
	FightProp34    *FightProp `csv:"Attribute34,omitempty"`     // 战斗属性34
	FightProp35    *FightProp `csv:"Attribute35,omitempty"`     // 战斗属性35
	FightProp36    *FightProp `csv:"Attribute36,omitempty"`     // 战斗属性36
	FightProp37    *FightProp `csv:"Attribute37,omitempty"`     // 战斗属性37
	FightProp38    *FightProp `csv:"Attribute38,omitempty"`     // 战斗属性38
	FightProp39    *FightProp `csv:"Attribute39,omitempty"`     // 战斗属性39
	FightProp40    *FightProp `csv:"Attribute40,omitempty"`     // 战斗属性40
	FightProp41    *FightProp `csv:"Attribute41,omitempty"`     // 战斗属性41
	FightProp42    *FightProp `csv:"Attribute42,omitempty"`     // 战斗属性42
	FightProp43    *FightProp `csv:"Attribute43,omitempty"`     // 战斗属性43
	FightProp44    *FightProp `csv:"Attribute44,omitempty"`     // 战斗属性44
	FightProp45    *FightProp `csv:"Attribute45,omitempty"`     // 战斗属性45
	FightProp46    *FightProp `csv:"Attribute46,omitempty"`     // 战斗属性46
	FightProp47    *FightProp `csv:"Attribute47,omitempty"`     // 战斗属性47
	FightProp48    *FightProp `csv:"Attribute48,omitempty"`     // 战斗属性48
	FightProp49    *FightProp `csv:"Attribute49,omitempty"`     // 战斗属性49
	FightProp50    *FightProp `csv:"Attribute50,omitempty"`     // 战斗属性50

	FightPropList []*FightProp `gorm:"-" csv:"-"` // 战斗属性列表
}

func (r *RoleConfig) TableName() string {
	return "config_role"
}

func (g *GameDataConfig) saveRoleConfig() {
	saveTableToDb[RoleConfig](g.Db, readTable[RoleConfig](g.CsvPathPrefix+"role.csv"))
}

func (g *GameDataConfig) loadRoleConfig() {
	g.GameDataMaps.RoleConfigMap = make(map[int32]*RoleConfig)
	for _, roleConfig := range loadTableFromDb[RoleConfig](g.Db) {
		roleConfig.FightPropList = make([]*FightProp, 0)
		if roleConfig.FightCycleProp != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightCycleProp)
		}
		if roleConfig.FightProp1 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp1)
		}
		if roleConfig.FightProp2 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp2)
		}
		if roleConfig.FightProp3 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp3)
		}
		if roleConfig.FightProp4 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp4)
		}
		if roleConfig.FightProp5 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp5)
		}
		if roleConfig.FightProp6 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp6)
		}
		if roleConfig.FightProp7 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp7)
		}
		if roleConfig.FightProp8 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp8)
		}
		if roleConfig.FightProp9 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp9)
		}
		if roleConfig.FightProp10 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp10)
		}
		if roleConfig.FightProp11 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp11)
		}
		if roleConfig.FightProp12 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp12)
		}
		if roleConfig.FightProp13 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp13)
		}
		if roleConfig.FightProp14 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp14)
		}
		if roleConfig.FightProp15 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp15)
		}
		if roleConfig.FightProp16 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp16)
		}
		if roleConfig.FightProp17 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp17)
		}
		if roleConfig.FightProp18 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp18)
		}
		if roleConfig.FightProp19 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp19)
		}
		if roleConfig.FightProp20 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp20)
		}
		if roleConfig.FightProp21 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp21)
		}
		if roleConfig.FightProp22 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp22)
		}
		if roleConfig.FightProp23 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp23)
		}
		if roleConfig.FightProp24 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp24)
		}
		if roleConfig.FightProp25 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp25)
		}
		if roleConfig.FightProp26 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp26)
		}
		if roleConfig.FightProp27 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp27)
		}
		if roleConfig.FightProp28 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp28)
		}
		if roleConfig.FightProp29 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp29)
		}
		if roleConfig.FightProp30 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp30)
		}
		if roleConfig.FightProp31 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp31)
		}
		if roleConfig.FightProp32 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp32)
		}
		if roleConfig.FightProp33 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp33)
		}
		if roleConfig.FightProp34 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp34)
		}
		if roleConfig.FightProp35 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp35)
		}
		if roleConfig.FightProp36 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp36)
		}
		if roleConfig.FightProp37 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp37)
		}
		if roleConfig.FightProp38 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp38)
		}
		if roleConfig.FightProp39 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp39)
		}
		if roleConfig.FightProp40 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp40)
		}
		if roleConfig.FightProp41 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp41)
		}
		if roleConfig.FightProp42 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp42)
		}
		if roleConfig.FightProp43 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp43)
		}
		if roleConfig.FightProp44 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp44)
		}
		if roleConfig.FightProp45 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp45)
		}
		if roleConfig.FightProp46 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp46)
		}
		if roleConfig.FightProp47 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp47)
		}
		if roleConfig.FightProp48 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp48)
		}
		if roleConfig.FightProp49 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp49)
		}
		if roleConfig.FightProp50 != nil {
			roleConfig.FightPropList = append(roleConfig.FightPropList, roleConfig.FightProp50)
		}

		g.GameDataMaps.RoleConfigMap[roleConfig.RoleId] = roleConfig
	}
	logger.Info("RoleConfig Count: %v", len(g.GameDataMaps.RoleConfigMap))
}

func GetRoleConfig(roleId int32) *RoleConfig {
	value, exist := CONF.GameDataMaps.RoleConfigMap[roleId]
	if !exist {
		logger.Error("[ConfigNotFound] RoleConfig, roleId: %v", roleId)
		return nil
	}
	return value
}

func GetRoleConfigMap() map[int32]*RoleConfig {
	return CONF.GameDataMaps.RoleConfigMap
}
